package com.example.androidshixi;

import android.os.Bundle;
import android.text.format.DateFormat;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

import java.util.Date;

public class ArticleDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_article_detail);

        TextView titleTextView = findViewById(R.id.article_detail_title_text_view);
        TextView authorTextView = findViewById(R.id.article_detail_author_text_view);
        TextView timeTextView = findViewById(R.id.article_detail_time_text_view);
        TextView contentTextView = findViewById(R.id.article_detail_content_text_view);

        // 获取传递过来的文章信息
        String title = getIntent().getStringExtra("title");
        String author = getIntent().getStringExtra("author");
        long timeStamp = getIntent().getLongExtra("time", 0);
        String content = getIntent().getStringExtra("content");

        // 格式化时间
        String formattedTime = DateFormat.format("yyyy年MM月dd日", new Date(timeStamp)).toString();

        // 设置文章详细信息
        titleTextView.setText(title);
        authorTextView.setText("作者: " + author);
        timeTextView.setText("时间: " + formattedTime);
        contentTextView.setText(content);
    }
}